//
//  LXHomeCenterItem.m
//  duoduo
//
//  Created by wanghao on 16/10/11.
//  Copyright © 2016年 LX. All rights reserved.
//

#import "LXHomeCenterItem.h"
#import "LXMapView.h"
#import "UIViewExt.h"

@interface LXHomeCenterItem ()
{
    UIView *cover_;
    UIButton *backBtn_;
    UIActivityIndicatorView *activityIndicatorView_;
    UILabel *lb_;
    UIView *back_;
}

@end

@implementation LXHomeCenterItem

/**
 *  初始化
 */

-(id)initWithTheFram:(CGRect)fram backImage:(NSString *)image
{

    if (self = [super init]) {
        self.frame = fram;
        self.backgroundColor = [UIColor clearColor];

        //[self setConnerByRediu:(self.height/2)];
//        UIImageView *backImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
//        backImage.image = [UIImage imageNamed:@"bubbles"];
//
//        //[backImage setConnerByRediu:self.height/2];
//        backImage.contentMode = UIViewContentModeScaleAspectFill;
//
//        [self addSubview:backImage];

        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height-6)];
        [btn setTitle:@"我的位置" forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:15];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn setConnerByRediu:self.height/2];
        [btn setBackgroundImage:[UIImage imageNamed:@"bg"] forState:UIControlStateNormal];

        btn.alpha = 0.8;
        UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(btn.frame.size.width/2-8, btn.frame.size.height, 16, 8)];
        imageView.image = [UIImage imageNamed:@"jiao"];
        [self addSubview:imageView];
        imageView.alpha = 0.8;
        [self addSubview:btn];
        [btn addTarget:self action:@selector(clickTheInsetBtn) forControlEvents:UIControlEventTouchUpInside];
        backBtn_ = btn;

        //有动画效果的遮盖
        cover_ = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
        [cover_ setConnerByRediu:self.height/2];
        cover_.backgroundColor  =[UIColor clearColor];
        [self addSubview:cover_];
        CGFloat active_H = 30;
        //  UIImageView *active_im = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, active_im_H, active_im_H)];
        UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] ;
        activityIndicatorView.frame = CGRectMake(0, 1, active_H, active_H);
        [activityIndicatorView setConnerRediu];
        [cover_ addSubview:activityIndicatorView];

        activityIndicatorView_ = activityIndicatorView;

//        UILabel *lb = [CJVITl
//                       creadALBwithFram:CGRectMake(activityIndicatorView.right, -4, self.width - active_H, self.height) andtext:@"正在加载..." andFont:12 andColor:[UIColor whiteColor] andAlmt:NSTextAlignmentLeft];
//        lb.backgroundColor  = [UIColor clearColor];
//        [cover_ addSubview:lb];
        cover_.hidden = YES;

    }
    return self;
}

/**
 *  点击按钮
 */
-(void)clickTheInsetBtn
{
    if (_hadClickTheInsetBtnBlock) {
        _hadClickTheInsetBtnBlock();
    }

}

/**
 *  重写 右边菊花转
 */
-(void)statAnimationToGetDatas
{    backBtn_.hidden = YES;
    cover_.hidden = NO;

    [activityIndicatorView_ startAnimating];
    [self setNeedsDisplay];

}

/**
 *  停止转菊花
 */
-(void)stopAnimation
{

    [activityIndicatorView_ stopAnimating];
    cover_.hidden = YES;
    backBtn_.hidden = NO;
    [self setNeedsDisplay];
}

@end
